package com.ruoyi.accounting.controller;

import com.ruoyi.accounting.domain.AccCurrencyInfo;
import com.ruoyi.accounting.service.AccCurrencyInfoService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 币种Controller
 *
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/currency")
public class AccCurrencyInfoController extends BaseController {
    @Autowired
    private AccCurrencyInfoService accCurrencyInfoService;

    /**
     * 查询币种列表
     */
    @RequiresPermissions("system:info:list")
    @GetMapping("/list")
    public TableDataInfo list(AccCurrencyInfo accCurrencyInfo) {
        startPage();
        List<AccCurrencyInfo> list = accCurrencyInfoService.selectAccCurrencyInfoList(accCurrencyInfo);
        return getDataTable(list);
    }

    /**
     * 导出币种列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "币种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccCurrencyInfo accCurrencyInfo) {
        List<AccCurrencyInfo> list = accCurrencyInfoService.selectAccCurrencyInfoList(accCurrencyInfo);
        ExcelUtil<AccCurrencyInfo> util = new ExcelUtil<AccCurrencyInfo>(AccCurrencyInfo.class);
        util.exportExcel(response, list, "币种数据");
    }

    /**
     * 获取币种详细信息
     */
    @RequiresPermissions("system:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(accCurrencyInfoService.selectAccCurrencyInfoById(id));
    }

    /**
     * 新增币种
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "币种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccCurrencyInfo accCurrencyInfo) {
        return toAjax(accCurrencyInfoService.insertAccCurrencyInfo(accCurrencyInfo));
    }

    /**
     * 修改币种
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "币种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccCurrencyInfo accCurrencyInfo) {
        return toAjax(accCurrencyInfoService.updateAccCurrencyInfo(accCurrencyInfo));
    }

    /**
     * 删除币种
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "币种", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accCurrencyInfoService.deleteAccCurrencyInfoByIds(ids));
    }

    /**
     * 批量新增币种
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "币种", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult add(@RequestBody List<AccCurrencyInfo> accCurrencyInfos) {
        return toAjax(accCurrencyInfoService.insertAccCurrencyInfo(accCurrencyInfos));
    }


}
